<?php
class Pageley_Commerce_Command_PlaceOrder extends Pageley_Controller_Command_TransactionalReadWrite {
	
	protected function executeInternal() {
		$order = $this->getSession()->get(Pageley_Commerce_Session::ORDER);
		if($order === null || $order->get("orderItems") === null || $order->get("orderItems")->isEmpty()) {
			throw new Pageley_Domain_Exception(new Pageley_I18n_Message("error.commerce.checkOutEmptyOrder"));
		}
		$order->place();
		$unitOfWork = $this->getUnitOfWork();
		$unitOfWork->register($order);
        $this->getSession()->remove(Pageley_Commerce_Session::ORDER);
        $model = new Pageley_Util_ArrayMap();
        $model->put("message", "orderPlaced");
        return new Pageley_Controller_ModelAndView($model);
	}
}